package com.dews.web.controller.information;

import com.dews.common.annotation.Log;
import com.dews.common.core.controller.BaseController;
import com.dews.common.core.domain.BaseResponse;
import com.dews.common.core.page.TableDataInfo;
import com.dews.common.enums.BusinessType;
import com.dews.common.utils.valid.AddGroup;
import com.dews.common.utils.valid.UpdateGroup;
import com.dews.information.domain.dto.ClazzInfoDTO;
import com.dews.information.domain.dto.ClazzInfoQueryDTO;
import com.dews.information.domain.vo.ClazzInfoVo;
import com.dews.information.service.IClazzInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 班级信息Controller
 * 
 * @author qingfeng
 * @date 2025-01-14
 */
@Api(value = "班级信息", tags = {"班级信息" })
@RestController
@Validated
@RequestMapping("/clazz/info")
public class ClazzInfoController extends BaseController {

    private IClazzInfoService clazzInfoService;

    @Autowired
    public ClazzInfoController(IClazzInfoService clazzInfoService) {
        this.clazzInfoService = clazzInfoService;
    }


    @ApiOperation(value = "获取班级信息列表")
    @PreAuthorize("@ss.hasPermi('clazz:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClazzInfoQueryDTO clazzInfoQueryDTO) {
        startPage();
        List<ClazzInfoVo> list = clazzInfoService.selectClazzInfoList(clazzInfoQueryDTO);
        return getDataTable(list);
    }

    @ApiOperation(value = "获取班级信息详细信息")
    @PreAuthorize("@ss.hasPermi('clazz:info:query')")
    @GetMapping(value = "/{id}")
    public BaseResponse getInfo(@PathVariable("id") Integer id) {
        return success(clazzInfoService.selectClazzInfoById(id));
    }

    @ApiOperation(value = "新增班级信息")
    @PreAuthorize("@ss.hasPermi('clazz:info:add')")
    @Log(title = "班级信息", businessType = BusinessType.INSERT)
    @PostMapping
    public BaseResponse add(@RequestBody @Validated(AddGroup.class) ClazzInfoDTO clazzInfoDTO) {
        return toAjax(clazzInfoService.insertClazzInfo(clazzInfoDTO));
    }

    @ApiOperation(value = "修改班级信息")
    @PreAuthorize("@ss.hasPermi('clazz:info:edit')")
    @Log(title = "班级信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public BaseResponse edit(@RequestBody @Validated(UpdateGroup.class) ClazzInfoDTO clazzInfoDTO) {
        return toAjax(clazzInfoService.updateClazzInfo(clazzInfoDTO));
    }

    @ApiOperation(value = "删除班级信息")
    @PreAuthorize("@ss.hasPermi('clazz:info:remove')")
    @Log(title = "班级信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public BaseResponse remove(@PathVariable List<Integer> ids) {
        return toAjax(clazzInfoService.deleteClazzInfoByIds(ids));
    }

    @ApiOperation(value = "年级集合")
    @GetMapping("/grade")
    public BaseResponse getGradeList() {
        return success(clazzInfoService.getGradeList());
    }


}
